package com.neborosoft.FlyingDog.logic.database.content.identified;

import com.neborosoft.lib.events.update.UpdatableValue;
import com.neborosoft.lib.utilities.Utilities;

public class Identified {
    private Identification id;

    public Object getId() {
        return id.getId();
    }

    public void setId(Object id){
        if(this.id.isIdSet()){
            throw new IllegalStateException("id reinitialisation is not allowed");
        }

        this.id.setId(id);
    }

    public void makeLocal(Object id){
        if(isLocal()){
            return;
        }

        this.id.setId(id);
        this.id.setIsLocal(true);
    }

    public Identified(boolean local){
        this.id = new Identification(null,local);
        Utilities.debugLogAllocation(this);
    }

    public Identified(boolean local, Object id) {
        this.id = new Identification(id, local);
        Utilities.debugLogAllocation(this);
    }

    public boolean isLocal(){
        return id.isLocal();
    }

    @Override
    public String toString() {
        return id.toString();
    }

    @Override
    protected void finalize() throws Throwable {
        Utilities.debugLogDeallocate(this);
    }
}
